package com.example.shortestpathalgorithm44;

import lombok.Getter;
import lombok.Setter;

import java.util.LinkedList;

/**
 * 有向有权图
 * @auther lijiewei
 * @date 2022/7/5 16:05
 */
@Setter
@Getter
public class Graph {

    //领接表
    private LinkedList<Edge>[] adj;

    //顶点个数
    private int v;

    public Graph(int v) {
        this.v = v;
        this.adj = new LinkedList[v];
        for (int i = 0; i < v; i++) {
            this.adj[i] = new LinkedList<>();
        }
    }

    /**
     * 添加一条边，s->t
     * @param s 起点
     * @param t 终点
     * @param w 权重
     * @return
     * @author lijiewei
     * @date   2022/7/12 16:24
     */
    public void addEdge(int s, int t, int w) {
        this.adj[s].add(new Edge(s, t, w));
    }

    public class Edge {
        //边的起始顶点编号
        public int sid;
        //边的终止顶点编号
        public int tid;
        //权重
        public int w;

        public Edge(int sid, int tid, int w) {
            this.sid = sid;
            this.tid = tid;
            this.w = w;
        }
    }


}
